﻿@page "/assets"

@using Flagrum.Web.Persistence.Entities
@using Flagrum.Web.Features.AssetExplorer.Base
@using Flagrum.Web.Features.AssetExplorer.Data
@using Flagrum.Web.Features.AssetExplorer.FileSystem
@using Flagrum.Web.Features.AssetExplorer.GameView
@using Flagrum.Core.Utilities.Types
@implements Flagrum.Web.Features.AssetExplorer.Base.IAssetExplorerParent

@inject FlagrumDbContext Context
@inject ProfileService Profile

<CascadingValue Value="this">
    @switch (CurrentView)
    {
        case AssetExplorerView.GameView:
            <AssetExplorer @ref="AssetExplorer">
                <AddressBarTemplate>
                    <GameViewAddressBar @ref="AssetExplorer.AddressBar"/>
                </AddressBarTemplate>
                <FileListTemplate>
                    <GameViewFileList @ref="AssetExplorer.FileList"/>
                </FileListTemplate>
            </AssetExplorer>
            break;
        case AssetExplorerView.FileSystem:
            <AssetExplorer @ref="AssetExplorer">
                <AddressBarTemplate>
                    <FileSystemAddressBar @ref="AssetExplorer.AddressBar"/>
                </AddressBarTemplate>
                <FileListTemplate>
                    <FileSystemFileList @ref="AssetExplorer.FileList"/>
                </FileListTemplate>
            </AssetExplorer>
            break;
        default:
            throw new ArgumentOutOfRangeException();
    }

</CascadingValue>

<AlertModal @ref="Alert"/>

@code
{
    public AlertModal Alert { get; set; }
    public AssetExplorer AssetExplorer { get; set; }

    public AssetExplorerView CurrentView { get; set; }

    public void CallStateHasChanged()
    {
        StateHasChanged();
    }

    protected override void OnInitialized()
    {
        CurrentView = Context.GetEnum<AssetExplorerView>(StateKey.CurrentAssetExplorerView);
    }
}